package com.longrise.android.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class PreferenceUtils 
{
	public static String getPrefString(String name, int mode,Context context, String key,String defaultValue) 
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		return settings.getString(key, defaultValue);
	}

	public static void setPrefString(String name, int mode,Context context,String key,String value)
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		settings.edit().putString(key, value).commit();
	}

	public static boolean getPrefBoolean(String name, int mode,Context context, String key, boolean defaultValue) {
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		return settings.getBoolean(key, defaultValue);
	}

	public static boolean hasKey(Context context, final String key)
	{
		return PreferenceManager.getDefaultSharedPreferences(context).contains(
				key);
	}

	public static void setPrefBoolean(String name, int mode,Context context, String key, boolean value)
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		settings.edit().putBoolean(key, value).commit();
	}

	public static void setPrefInt(String name, int mode,Context context, String key, int value) 
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		settings.edit().putInt(key, value).commit();
	}

	public static int getPrefInt(String name, int mode,Context context, String key, int defaultValue) 
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		return settings.getInt(key, defaultValue);
	}

	public static void setPrefFloat(String name, int mode,Context context, String key, float value)
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		settings.edit().putFloat(key, value).commit();
	}

	public static float getPrefFloat(String name, int mode,Context context, String key, float defaultValue)
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		return settings.getFloat(key, defaultValue);
	}

	public static void setSettingLong(String name, int mode,Context context, String key, long value) 
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		settings.edit().putLong(key, value).commit();
	}

	public static long getPrefLong(String name, int mode,Context context, String key, long defaultValue)
	{
		SharedPreferences settings = context.getSharedPreferences(name, mode);
		return settings.getLong(key, defaultValue);
	}

	public static void clearPreference(Context context, SharedPreferences p)
	{
		Editor editor = p.edit();
		editor.clear();
		editor.commit();
	}
}
